package com.jvm.jconsole;

import java.util.concurrent.*;

// 饥饿死锁例子
public class ExecutorLock {

    // 只有一个线程的线程池
    private static ExecutorService single = Executors.newSingleThreadExecutor();

    public static class AnotherCallable implements Callable<String> {

        @Override
        public String call() throws Exception {
            System.out.println("int AnotherCallable");

            return "another success";
        }
    }

    public static class MyCallable implements Callable<String> {

        @Override
        public String call() throws Exception {
            System.out.println("in MyCallable");
            Future<String> submit = single.submit(new AnotherCallable());

            return "success: " + submit.get();
        }
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable task = new MyCallable();

        Future<String> submit = single.submit(task);

        System.out.println(submit.get());
        System.out.println("over");
        single.shutdown();
    }

}
